package com.yunhaikeji.api.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.FileNotFoundException;

@Configuration
public class UploadFilePathConfig implements WebMvcConfigurer {


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String serverPath = "";
        try {
            serverPath = ResourceUtils.getURL("api/src/main/resources/static").getPath();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        registry.addResourceHandler("static/**").addResourceLocations("file:" + serverPath);
    }

}
